import { Injectable, OnApplicationShutdown } from '@nestjs/common';
import neo4j, { Driver,Transaction,QueryResult, Record } from 'neo4j-driver'

@Injectable()
export class Neo4jService {
    private static driver = null;
   
    getDriver() {
        if (Neo4jService.driver != null) {
            return Neo4jService.driver;
        }
        const dbHost = process.env.Neo4j_DB_HOST || 'localhost'
        const dbPort = process.env.Neo4j_DB_PORT || '7687'
        const uri = `bolt://${dbHost}:${dbPort}`
        const user = process.env.Neo4j_DB_USER || 'neo4j'
        const password = process.env.Neo4j_DB_PASS || 'password'

        const driver = neo4j.driver(uri, neo4j.auth.basic(user, password))
        Neo4jService.driver = driver;
        //console.log(dbHost,dbPort,uri,user,password)

        return Neo4jService.driver;
        
    }
    
    //onApplicationShutdown() {
      //  return this.getDriver().close()
//    }
}
